﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLTV_BLL;
using QLTV_Public;

namespace QLTV_GiaoDien
{
    public partial class uc_Lop : DevExpress.XtraEditors.XtraUserControl
    {
        public uc_Lop()
        {
            InitializeComponent();
        }
        public void GetLoad(int kt)
        {
            txt_Load.Text = kt.ToString();
        }
        Lop_BLL lop_bll = new Lop_BLL();
        private void uc_Lop_Load(object sender, EventArgs e)
        {
            gridControl1.DataSource = lop_bll.LayDuLieu();
            txt_Load.Hide();
        }
        private void bbi_Them_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_Lop f = new frm_Lop();

            f.Flag = 0;
            f.MyGetDaTa = new frm_Lop.GetInt(GetLoad);
            f.ShowDialog();
        }

        private void bbi_Sua_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_Lop f = new frm_Lop();
            f.Flag = 1;
            f.MyGetDaTa = new frm_Lop.GetInt(GetLoad);
            f.MaLop = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Lớp").ToString());
            f.TenLop =gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Lớp").ToString();
            f.TenDonVi = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Đơn Vị").ToString();
            f.KhoaHoc = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Khóa Học").ToString();
            f.GhiChu = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ghi Chú").ToString();
            f.ShowDialog();
        }

        private void bbi_Xem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_Lop f = new frm_Lop();
            f.Flag = 2;
            f.MyGetDaTa = new frm_Lop.GetInt(GetLoad);
            f.MaLop = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Lớp").ToString());
            f.TenLop = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Lớp").ToString();
            f.TenDonVi = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Đơn Vị").ToString();
            f.KhoaHoc = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Khóa Học").ToString();
            f.GhiChu = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ghi Chú").ToString();
            f.ShowDialog();
        }
        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            frm_Lop f = new frm_Lop();
            f.Flag = 2;
            f.MyGetDaTa = new frm_Lop.GetInt(GetLoad);
            f.MaLop = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Lớp").ToString());
            f.TenLop = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Lớp").ToString();
            f.TenDonVi = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Đơn Vị").ToString();
            f.KhoaHoc = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Khóa Học").ToString();
            f.GhiChu = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ghi Chú").ToString();
            f.ShowDialog();
        }
        private void txt_Load_TextChanged(object sender, EventArgs e)
        {
            if (txt_Load.Text == "1")
            {
                uc_Lop_Load(sender,e);
                txt_Load.Text = "0";
            }
        }
        NhatKy_BLL nhatKy_bll = new NhatKy_BLL();
        TrungGian tg = new TrungGian();
        NhatKy_Public nk = new NhatKy_Public();
        private void bbi_Xoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

            Lop_Public f = new Lop_Public();
            f.MaLop = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Lớp").ToString());
            f.TenLop = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Lớp").ToString();
            if (XtraMessageBox.Show("Bạn có muốn xóa Tên lớp: '" + f.TenLop + "' có Mã lớp là : '" + f.MaLop + "' này không?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {

                lop_bll.Delete_Lop(f);
                //
                string d = DateTime.Now.ToString();
                nk.MaNV = tg.MaNV;
                nk.NgayGio = d;
                nk.HanhDong = "Xóa";
                nk.MoTa = "Xóa thông tin của lớp:'" + f.TenLop + "'";
                nhatKy_bll.insert_nhatKy(nk, nk, nk, nk);
                //
                uc_Lop_Load(sender, e);
            }
        }




    }
}
